package com.mayi.vo;

import java.util.HashMap;
import java.util.Map;

/**
 * @Description:
 * @Auther: yacong_liu
 * @Date: 2019/7/11
 * @version: 1.0
 */
public class Result {

    private Integer code;
    private String msg;
    private Map<String, Object> data = new HashMap<>();

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Map<String, Object> getData() {
        return data;
    }

    public void setData(Map<String, Object> data) {
        this.data = data;
    }


    /**
     * 成功
     */
    public static Result success() {
        Result result = new Result();
        result.setCode(ResultEnums.OK.getCode());
        result.setMsg(ResultEnums.OK.getMessage());
        return result;
    }

    /**
     * 内部错误(参数错误)
     */
    public static Result error() {
        Result result = new Result();
        result.setCode(ResultEnums.ERROR.getCode());
        result.setMsg(ResultEnums.ERROR.getMessage());
        return result;
    }

    /**
     * 功能描述: 自定义错误信息<br>
     *
     * @Param:
     * @Return:
     * @Author: yacong_liu
     * @Date: 2019/7/14 12:00
     */
    public static Result error(String msg) {
        Result result = new Result();
        result.setCode(ResultEnums.ERROR.getCode());
        result.setMsg(msg);
        return result;
    }

    public Result add(String key, Object value) {
        this.getData().put(key, value);
        return this;
    }
}
